import json
import re
import hashlib
from django.contrib.auth.hashers import pbkdf2
from django.contrib.auth.hashers import make_password, check_password
from datetime import datetime, timedelta
# from apps.utils.generate_account_number import GenerateAccountNumber
from rest_framework import serializers
from rest_framework.validators import UniqueValidator
from django.contrib.auth import get_user_model
# from rest_framework_jwt.utils import jwt_encode_handler, jwt_payload_handler
from rest_framework_jwt.serializers import jwt_encode_handler, jwt_payload_handler
# from rest_framework_jwt.views import obtain_jwt_token
from django.db.models import Q
from django.db import transaction
from common.com_utils import Utils
from common.com_time import Time
from apps.resources.models import CarInfoModel, FixedStationInfoModel, TipsInfoModel


class CarInfoSerializers(serializers.ModelSerializer):
    """
    车辆信息序列化类
    """

    @transaction.atomic
    def validate(self, attrs):
        if attrs.get('created_time', None) is None:
            attrs['created_time'] = Time.current_datetime_str()
        return attrs

    class Meta:
        model = CarInfoModel
        fields = "__all__"


class FixedStationInfoSerializers(serializers.ModelSerializer):
    """
    固定站点信息序列化类
    """

    @transaction.atomic
    def validate(self, attrs):
        if attrs.get('created_time', None) is None:
            attrs['created_time'] = Time.current_datetime_str()
        return attrs

    class Meta:
        model = FixedStationInfoModel
        fields = "__all__"


class TipsInfoSerializers(serializers.ModelSerializer):
    """
    提醒信息序列化类
    """

    @transaction.atomic
    def validate(self, attrs):
        if attrs.get('created_time', None) is None:
            attrs['created_time'] = Time.current_datetime_str()
        return attrs

    class Meta:
        model = TipsInfoModel
        fields = "__all__"
